/*
 * Copyright (C) 2011, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.interpreter.backends.rete;

import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author Laurent WOUTERS
 */
public abstract class JoinStrategy {
    protected BetaJoinNodeTest test1;
    protected BetaJoinNodeTest test2;
    protected BetaJoinNodeTest test3;
    
    public JoinStrategy(BetaJoinNodeTest t1, BetaJoinNodeTest t2, BetaJoinNodeTest t3) {
        this.test1 = t1;
        this.test2 = t2;
        this.test3 = t3;
    }
    
    protected boolean passTests(Token token, TripleFact fact) {
        if (test1 == null) return true;
        if (!test1.check(token, fact)) return false;
        if (test2 == null) return true;
        if (!test2.check(token, fact)) return false;
        if (test3 == null) return true;
        return test3.check(token, fact);
    }
    
    public abstract Iterator<Couple> join(Collection<Token> tokens, Collection<TripleFact> facts);
}
